﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WenZ.Base;
using WenZ.Model;

namespace WenZ.ViewModel
{
    public class SystemMonitorViewModel : NotifyPropertyBase
    {

        public ObservableCollection<LogModel> LogList { get; set; } = new ObservableCollection<LogModel>();

        private DeviceModel _currentDevice;

        public DeviceModel CurrentDevice
        {
            get { return _currentDevice; }
            set { _currentDevice = value; this.RaisePropertyChanged(); }
        }

        private bool _isShowDetail = false;

        public bool IsShowDetail
        {
            get { return _isShowDetail; }
            set { _isShowDetail = value; this.RaisePropertyChanged(); }
        }

        public DeviceModel TestDevice { get; set; }

        public CommandBase CompontentCommand { get; set; }
        public SystemMonitorViewModel()
        {
            InitLogInfo();

            this.CompontentCommand = new CommandBase(new Action<object>(DoTowerCommand));

            #region 测试数据
            TestDevice =new DeviceModel();
            TestDevice.DeviceName = "冷却塔 1#";
            TestDevice.IsRunning = true;
            TestDevice.IsWarning = true;
            TestDevice.MonitorValueList.Add(new MonitorValueModel
            {
                ValueId = "1",
                ValueName = "液位",
                Unit ="m",
                CurrentValue = 45,
                Values = new LiveCharts.ChartValues<LiveCharts.Defaults.ObservableValue> { new
                LiveCharts.Defaults.ObservableValue(0), new LiveCharts.Defaults.ObservableValue(1)}
            });
            TestDevice.MonitorValueList.Add(new MonitorValueModel
            {
                ValueId = "1",
                ValueName = "入口压力",
                Unit = "Mpa",
                CurrentValue = 34,
                Values = new LiveCharts.ChartValues<LiveCharts.Defaults.ObservableValue> { new
                LiveCharts.Defaults.ObservableValue(0), new LiveCharts.Defaults.ObservableValue(0)}
            });
            TestDevice.MonitorValueList.Add(new MonitorValueModel
            {
                ValueId = "1",
                ValueName = "入口温度",
                Unit = "℃",
                CurrentValue = 34,
                Values = new LiveCharts.ChartValues<LiveCharts.Defaults.ObservableValue> { new 
                LiveCharts.Defaults.ObservableValue(0), new LiveCharts.Defaults.ObservableValue(0)}
            });
            TestDevice.MonitorValueList.Add(new MonitorValueModel
            {
                ValueId = "1",
                ValueName = "出口压力",
                Unit = "Mpa",
                CurrentValue = 34,
                Values = new LiveCharts.ChartValues<LiveCharts.Defaults.ObservableValue> { new
                LiveCharts.Defaults.ObservableValue(0), new LiveCharts.Defaults.ObservableValue(0)}
            });
            TestDevice.MonitorValueList.Add(new MonitorValueModel
            {
                ValueId = "1",
                ValueName = "出口温度",
                Unit = "℃",
                CurrentValue = 34,
                Values = new LiveCharts.ChartValues<LiveCharts.Defaults.ObservableValue> { new
                LiveCharts.Defaults.ObservableValue(0), new LiveCharts.Defaults.ObservableValue(0)}
            });
            TestDevice.WarningMessageList.Add(new WarningMessageModel { Message = "冷却塔1#液位极低，当前值：0" });
            TestDevice.WarningMessageList.Add(new WarningMessageModel { Message = "冷却塔1#入口压力极低，当前值：0" });
            TestDevice.WarningMessageList.Add(new WarningMessageModel { Message = "冷却塔1#入口温度低，当前值：0" });
            #endregion
        }

        private void InitLogInfo()
        {
            this.LogList.Add(new LogModel { RowNumber = 1, DeviceName = "冷却塔1#", LogInfo = "已启动", LogType = Base.LogType.Info });
            this.LogList.Add(new LogModel { RowNumber = 2, DeviceName = "冷却塔2#", LogInfo = "已启动", LogType = Base.LogType.Info });
            this.LogList.Add(new LogModel { RowNumber = 3, DeviceName = "冷却塔3#", LogInfo = "液位极低", LogType = Base.LogType.Warn });
            this.LogList.Add(new LogModel { RowNumber = 4, DeviceName = "循环水泵1#", LogInfo = "频率过大", LogType = Base.LogType.Warn });
            this.LogList.Add(new LogModel { RowNumber = 5, DeviceName = "循环水泵2#", LogInfo = "已启动", LogType = Base.LogType.Info });
            this.LogList.Add(new LogModel { RowNumber = 6, DeviceName = "循环水泵3#", LogInfo = "已启动", LogType = Base.LogType.Info });
        }

        private void DoTowerCommand(object param) 
        {
            CurrentDevice = param as DeviceModel;
            this.IsShowDetail = true;   
        }
    }
}
